<template>
    <div class="container">
        <div class="product-detail">
            <header>
                <router-link to="/">首页 / </router-link>
                <router-link to="/loan/product">借贷需求 / </router-link>
                <router-link :to="{ path: '/loan/product'}">{{detail.productName?detail.productName:'--'}}/ </router-link>
                基础信息
            </header>
            <div v-if="messageList.length > 0" class="focus-pointer mb30">
                <div class="flex-box-align" style="padding-left: 18px; position: relative; width: 100%;">
                    今日要事：
                    <div class="message">
                        <ul class="marquee_list" :style="{ top: -num + 'px'}" :class="{marquee_top:num}">
                            <li v-for="(item, index) in messageList" :key="index" v-if="messageList && messageList.length">
                                <router-link :to="{name: item.route}">{{item.showMsg}}</router-link>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="detail-display">
                <div class="flex-box-align head-sec">
                    <div class="flex">{{detail.productName}} <span style="margin-left:10px">{{detail.gmtCreated}}</span></div>
                    <div>
                        <el-button type="primary" style="background-color: #ED7018;border-color: #ED7018;" @click="$router.push('/loan/productEdit?id='+id)">编辑</el-button>
                        <el-button type="primary" style="background-color: #ED7018;border-color: #ED7018;" @click="handleChangeStatus(detail.status)" v-if="detail.status == 'off'">上架</el-button>
                        <el-button type="primary" style="background-color: #ED7018;border-color: #ED7018;" @click="handleChangeStatus(detail.status)" v-else>下架</el-button>
                    </div>
                </div>
                <div style="padding-top: 30px;">
                    <div class="flex-box-container">
                        <div class="flex" style="margin-right: 40px;">
                            <div class="whiteSpace mb30">
                                <span>贷款额度：</span>
                                <span>{{detail.loanFundMin}}万 ~ {{detail.loanFundMax}}万</span>
                            </div>
                            <div class="whiteSpace mb30">
                                <span>贷款年化利率：</span>
                                <span>{{detail.minReportRate}}%/年</span>
                            </div>
                            <div class="whiteSpace mb30">
                                <span>资金主体：</span>
                                <span>{{fundBody}}</span>
                            </div>
                            <div class="whiteSpace mb30">
                                <span>投资行业：</span>
                                <span>{{detail.firstIndustryDesc ? detail.firstIndustryDesc : ''}}{{detail.secondIndustryDesc ? detail.secondIndustryDesc : ''}}{{detail.thirdIndustryDesc ? detail.thirdIndustryDesc : ''}}</span>
                            </div>
                        </div>
                        <div class="flex">
                            <!--<div class="whiteSpace mb30">-->
                                <!--<span>总投资金额：</span>-->
                                <!--<span>{{detail.totalInvestFund}}</span>-->
                            <!--</div>-->
                            <div class="whiteSpace mb30">
                                <span>贷款适用地区：</span>
                                <span>{{area.join(';')}}</span>
                            </div>
                            <div class="whiteSpace mb30">
                                <span>申请者最低成立年限：</span>
                                <span>{{detail.applyMixYear + '年'}}</span>
                            </div>
                            <div class="whiteSpace mb30">
                                <span>申请者盈利要求：</span>
                                <span v-if="detail.applyProfit == 'y'">需盈利</span>
                                <span v-else>无要求</span>
                            </div>
                            <div class="whiteSpace mb30">
                                <span>申请者最低营业收入要求：</span>
                                <span>{{detail.applyMixIncome}}</span>
                            </div>

                        </div>
                    </div>
                    <div class="mb30 flex-box-container">
                        <span class="whiteSpace">贷款产品详细说明：</span>
                        <span v-html="detail.memo" class="flex"></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {parseUrlParams} from "../../util";
    let CONSTANT = require('../../constant/constant.js'),
        common = require('../../common.js');
    import VDistpicker from 'v-distpicker';

    export default {
        data() {
            return {
                id: "",
                detail: {},
                province: "",
                city: "",
                district: "",
                imageUrl: require("../../images/upload-default.png"),
                fundBody: "",
                num: 0,
                messageList: [],
                area: []
            }
        },
        mounted(){
            this.getMessage()
            setInterval( () => {
                this.getMessage()
            }, 120000)
            this.id = parseUrlParams("id");
            this.getDetail()
        },
        components: {
            VDistpicker
        },
        methods:{
            getMessage() {
                let url = CONSTANT.URL.CALENDAR.MESSAGELIST;
                common.requestAjax(url, {}, {}, (data) => {
                    if(data.status == 200) {
                        this.messageList = data.data.bussData;
                        this.showMarquee(this.num)
                    }
                })
            },
            returnPrice(num){
                return common.returnNum(num)
            },
            getDetail() {
                let url = CONSTANT.URL.FINANCE.PRODUCTDETAIL;
                common.requestAjax(url, {id: parseUrlParams("id")}, {}, (data) => {
                    this.detail = data.data.bussData
                    let arr = [];
                    this.detail.fundBodyDatas.map( item => {
                        arr.push(item.fundBodyDesc)
                    })
                    this.detail.areaDatas.map( (item, index) => {
                        let itemArea = "";
                        if (item.financingProvinceName) {
                            itemArea = item.financingProvinceName
                        }
                        if (item.financingCityName) {
                            itemArea = item.financingProvinceName+item.financingCityName
                        }
                        if (item.financingDistrictName) {
                            itemArea = item.financingProvinceName+item.financingCityName+item.financingDistrictName
                        }
                        this.area.push(itemArea)
                    })
                    this.fundBody = arr.join(";")
                })
            },
            handleChangeStatus(status) {
                let url = CONSTANT.URL.COMPANY.ONOFFUSER;
                common.requestAjax(url, JSON.stringify({productId: parseUrlParams("id"), status: status}), {}, (data) => {
                    if (data.status == 200) {
                        this.$message({
                            message: data.msg,
                            type: 'success'
                        })
                        this.getDetail()
                    }
                })
            },
            showMarquee:function (num) {
                if (!this.messageList[0]) return
                this.messageList.push(this.messageList[0]);
                var max = this.messageList.length;
                var that = this;
                let marqueetimer =  setInterval(function(){
                    num++;
                    if(num>=max ){
                        num=0;
                    }
                    that.num=num*30;
                }, 2000);
            }
        }
    }
</script>

<style lang="scss">
    .message {
        display: block;
        position: relative;
        width: 60%;
        height: 30px;/*关键样式*/
        overflow: hidden;
    }
    .marquee_list{
        display: block;
        position: absolute;
        top:0;
        left: 0;
    }
    .marquee_top{transition: top 0.5s ;}/*关键样式*/
    .marquee_list li{
        height: 30px;/*关键样式*/
        line-height: 30px;/*关键样式*/
        font-size: 14px;
        padding-left: 20px;
        background-color: #fff;
        a {
            color: #333;
        }
    }
    .container {
        .mb30 {
            margin-bottom: 30px;
        }
        .whiteSpace {
            white-space: nowrap;
        }
        .product-detail {
            header {
                margin: 19px 0;
                font-size: 14px;
                color: #333;
                a {
                    color: #999;
                }
            }
            .focus-pointer {
                font-size: 14px;
                height: 70px;
                line-height: 70px;
                background-color: #fff;
                padding-left: 18px;
                white-space: nowrap;
            }
            .detail-display {
                background-color: #fff;
                padding: 23px;
                .head-sec {
                    padding-bottom: 8px;
                    border-bottom: 1px solid #e1e1e1;
                }
            }
            .top-manager {
                margin-bottom: 20px;
                span {
                    width: 80px;
                    display: inline-block;
                }
            }
        }
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
    }
</style>
